package com.atguigu.lease.sustom.converter;

import com.atguigu.lease.model.enums.LeaseStatus;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @ClassName StringToItemTypeConverter
 * @Author admin
 * @Date 2024/6/9
 */
@Component
public class StringToLeaseStatusConverter implements Converter<String, LeaseStatus> {
    @Override
    public LeaseStatus convert(String source) {
        return Arrays.stream(LeaseStatus.values()).filter(leaseStatus -> source.equals(String.valueOf(leaseStatus.getCode()))).findFirst().orElseThrow(IllegalArgumentException::new);
    }
}
